package com.novunda.platform.services;

import com.novunda.platform.common.utils.DictUtils;
import com.novunda.platform.common.utils.UserUtils;
import com.novunda.platform.entities.Dict;
import com.novunda.platform.entities.Menu;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * @author linfeng
 * @since 2016/8/31
 */
@Service
public class UserMenus implements Serializable {
    private static final long serialVersionUID = 1566423126340217492L;

    public List<Menu> getHorizantalMenu() {
        return UserUtils.getHorizantalMenu();
//    	return UserUtils.getMenuList();
    }

    public boolean selected(Menu menu, String currentMenuPath) {
        if (StringUtils.isBlank(currentMenuPath) || menu == null
                || StringUtils.isBlank(menu.getParentIds())) {
            return false;
        }
        String parentIds = "," + menu.getParentIds() + menu.getId() + ",";
        String currentMenuPaths = "," + currentMenuPath + ",";
        return currentMenuPaths.contains(parentIds);
    }

    public List<Dict> getDictList(String type) {

        return DictUtils.getDictList(type);
    }

    public static String getDictLabel(String value, String type, String defaultValue){

        return DictUtils.getDictLabel(value, type, defaultValue);
    }

}
